//
//  AudioListTableViewCell.m
//  AudioBook_A
//
//  Created by Sansan on 15/4/16.
//  Copyright (c) 2015年 Sansan. All rights reserved.
//

#import "AudioListTableViewCell.h"

@implementation AudioListTableViewCell

// 初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    
    return self;
}


- (void)creatView
{
    
    //self.contentView.backgroundColor = [UIColor greenColor];
    self.cellView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenFram.width, 80)];
    self.cellView.backgroundColor = [UIColor colorWithRed:237/255.0 green:244/255.0 blue:246/255.0 alpha:1.0];
    //self.cellView.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.cellView];
    
    self.cellImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, 80, 78)];
    //self.cellImageView.backgroundColor = [UIColor redColor];
    [self.cellView addSubview:self.cellImageView];
    
    
    // 创建"辑"的图标
    UIView *picJi = [[UIView alloc] initWithFrame:CGRectMake(105, 20, 30, 30)];
    UIImageView *picJiImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sound_album@2x.png"]];
    [picJi addSubview:picJiImageView];
    [self.cellView addSubview:picJi];
    
    self.cellNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(135, 15, 200, 30)];
    [self.cellView addSubview:self.cellNameLabel];
    
    
    self.cellplaysCountsLabel = [[UILabel alloc] initWithFrame:CGRectMake(150, 50, 45, 20)];
    [self.cellView addSubview:self.cellplaysCountsLabel];
    
    // 创建播放的图标(不是button)
    UIView *playsCountView = [[UIView alloc] initWithFrame:CGRectMake(130, 50, 20, 20)];
    UIImageView *playCountImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lllll.png"]];
    [playsCountView addSubview:playCountImageView];
    // playsCountView.backgroundColor = [UIColor yellowColor];
    [self.cellView addSubview:playsCountView];
    
    // 创建收听的图标(不是button)
    UIView *tracksCountsView = [[UIView alloc] initWithFrame:CGRectMake(216, 50, 20, 20)];
    UIImageView *tracksCountsImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"albumInfoCell_tracks_mark@2x.png"]];
    // tracksCountsView.backgroundColor = [UIColor yellowColor];
    [tracksCountsView addSubview:tracksCountsImageView];
    [self.cellView addSubview:tracksCountsView];
    
    self.celltracksCountsLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 50, 40, 20)];
    // self.celltracksCountsLabel.backgroundColor = [UIColor lightGrayColor];
    [self.cellView addSubview:self.celltracksCountsLabel];
    
    // 收藏的button
    self.collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.collectButton.frame = CGRectMake(320, 45, 25, 25);
    // self.collectButton.backgroundColor = [UIColor orangeColor];
    [self.collectButton setBackgroundImage:[UIImage imageNamed:@"iconfont-collectkogn.png"] forState:UIControlStateNormal];
    [self.collectButton addTarget:self action:@selector(collectionButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.cellView addSubview:self.collectButton];
    
}

// 收藏触发的方法
- (void)collectionButtonAction
{
    NSLog(@"收藏按钮触发的方法");
}



// 加载图片
- (void)setModel:(AudioListModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    
    self.cellNameLabel.text = model.title;
    self.cellNameLabel.font = [UIFont systemFontOfSize:14];
    
    self.cellplaysCountsLabel.text = [NSString stringWithFormat:@"%.2f万", model.playsCounts/10000.0];
    self.cellplaysCountsLabel.font = [UIFont systemFontOfSize:10];
    
    
    self.celltracksCountsLabel.text = [NSString stringWithFormat:@"%ld", model.tracksCounts];
    self.celltracksCountsLabel.font = [UIFont systemFontOfSize:10];
    
    
    [self.cellImageView sd_setImageWithURL:[NSURL URLWithString:_model.albumCoverUrl290] placeholderImage:[UIImage imageNamed:@"bg_albumView_header.png"]];
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
